#include "QSerializedProperty.h"

using namespace QPE;

QSerializedProperty::QSerializedProperty()
	: ID(), Type(), Value()
{
}

/*! Creates a new QSerializedProperty from an existing property

*/
QSerializedProperty::QSerializedProperty(const QProperty* property, const QPropertySet* set)
	: ID(), Type(property ? property->type() : QString()), Value(property ? property->getValue() : QVariant())
{
	if(set) {
		ID = set->getPropertyID(property);

		initChildren(property, set);
	}
}

QSerializedProperty::QSerializedProperty(const QProperty *property, const QString &id, const QPropertySet *set)
	: ID(id), Type(property ? property->type() : QString()), Value(property ? property->getValue() : QVariant())
{
	initChildren(property, set);
}

QSerializedProperty::QSerializedProperty(const QString &id, const QString &type, const QVariant &value)
	: ID(id), Type(type), Value(value)
{
}

QPE::QSerializedProperty::~QSerializedProperty()
{
	//
}

void QSerializedProperty::initChildren(const QProperty *property, const QPropertySet *set)
{
	if(property && set) {
		const QList<QProperty*>& tmpChildren = property->getChildren();
		foreach(const QProperty* tmpChild, tmpChildren) {
			QString tmpChildID = set->getPropertyID(property);
			Children.append(QSerializedProperty(tmpChild, tmpChildID, set));
		}
	}
}

